package com.documents.main.action;

import com.documents.common.core.PageBean;
import com.documents.common.core.action.BaseActionSupport;
import com.documents.pojo.DocumentGroup;
import com.documents.service.document.DocumentGroupService;
import java.util.List;
import org.apache.struts2.interceptor.ServletRequestAware;

/**
 *
 * @author sunying
 */
public class DocumentPropertyAction extends BaseActionSupport implements ServletRequestAware {

    private static final long serialVersionUID = 1003L;
    private DocumentGroupService documentGroupService;
    private List<DocumentGroup> allDocumentGroup;
    private List<DocumentGroup> documentGroupList;
    private Integer flag = 0;
    private Integer parentId = 0;
    private int page=1;
    private PageBean pageBean;
    private int pageSize = 20;
    private DocumentGroup property;
    private String jsonDataString;
    private String actionURI;
    private int propertyId;



    public List<DocumentGroup> getDocumentGroupList() {
        return documentGroupList;
    }

    public void setDocumentGroupList(List<DocumentGroup> documentGroupList) {
        this.documentGroupList = documentGroupList;
    }

    public int getPropertyId() {
        return propertyId;
    }

    public void setPropertyId(int propertyId) {
        this.propertyId = propertyId;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public String getActionURI() {
        return actionURI;
    }

    public void setActionURI(String actionURI) {
        this.actionURI = actionURI;
    }

    public String main() throws Exception {
        return "success";
    }

    public String top() throws Exception {
        this.allDocumentGroup = documentGroupService.findAll();
        return "success";
    }

    public String list() throws Exception {

        pageBean = documentGroupService.getPageBean(page, pageSize, property);

        return SUCCESS;
    }

    public void deleteById() {

        documentGroupService.deleteById(property.getId());
    }

    public String addInput() throws Exception {
        actionURI = "save";

        return SUCCESS;
    }

    public String updateInput() throws Exception {
        actionURI = "update";
        property = documentGroupService.get(propertyId);
        if (property == null) {
            return ERROR;
        } else {
            return SUCCESS;
        }
    }

    public void getPropertyJson() {
        jsonDataString = this.documentGroupService.getAllJSONArray().toString();
    }

    public String save() throws Exception {
        documentGroupService.saveInstance(property);
        return SUCCESS;
    }

    public String update() throws Exception {
        documentGroupService.updateInstance(property);
        return SUCCESS;
    }

    public List<DocumentGroup> getAllDocumentGroup() {
        return this.allDocumentGroup;
    }

    public void setAllDocumentGroup(List<DocumentGroup> allDocumentGroup) {
        this.allDocumentGroup = allDocumentGroup;
    }

    public DocumentGroup getProperty() {
        return property;
    }

    public void setProperty(DocumentGroup property) {
        this.property = property;
    }

    public List<DocumentGroup> getDocumentTypeList() {
        return documentGroupList;
    }

    public void setDocumentTypeList(List<DocumentGroup> documentGroupList) {
        this.documentGroupList = documentGroupList;
    }

    public DocumentGroupService getDocumentGroupService() {
        return documentGroupService;
    }

    public void setDocumentGroupService(DocumentGroupService documentGroupService) {
        this.documentGroupService = documentGroupService;
    }

    public Integer getFlag() {
        return flag;
    }

    public void setFlag(Integer flag) {
        this.flag = flag;
    }

    public String getJsonDataString() {
        return jsonDataString;
    }

    public void setJsonDataString(String jsonDataString) {
        this.jsonDataString = jsonDataString;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public PageBean getPageBean() {
        return pageBean;
    }

    public void setPageBean(PageBean pageBean) {
        this.pageBean = pageBean;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPid() {
        return parentId;
    }

    public void setPid(Integer pid) {
        this.parentId = pid;
    }
}
